package com.aat.restful.springresteasy.web;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.aat.restful.springresteasy.bean.Book;
import com.aat.restful.springresteasy.service.BookService;
import com.aat.restful.springresteasy.service.TestService;


@Path("/test")
@Controller
public class TestController extends BaseController{
	@Autowired
	private TestService testService;

	@Autowired
	private BookService bookService;

	@GET
	@Path("test")
	@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
	public String test(@QueryParam("s") String s) {
		return testService.say("hello "+s);
	}
	
	@POST
	@Path("post")
	@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
	@Consumes(MediaType.APPLICATION_JSON )
	public String post(@Context HttpHeaders headers,String json) {
		System.out.println("3"+json);
		return testService.say("post "+json);
	}

	@GET
	@Path("book")
	@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
	public List<Book> book(@Context HttpHeaders headers) {
		System.out.println(getIP(headers));
		return bookService.getAll();
	}

}
